use std::sync::mpsc;
use std::thread;

use rand::Rng;

fn main() {
    let (tx, rx) = mpsc::channel();
    let sender2 = tx.clone();
    thread::spawn(move || {
        for _ in 0..10 {
            let msg = String::from(format!("thread1:HI"));
            tx.send(msg).unwrap();
        }
    });
    thread::spawn(move || {
        for _ in 0..10 {
            let msg = String::from(format!("thread2: nihao"));
            sender2.send(msg).expect("发送消息发生意外");
        }
    });
    for msg in rx {
        println!("接受消息: {}", msg);
    }
}

fn generate_random_word() -> String {
    let vowels = ['a', 'e', 'i', 'o', 'u'];
    let consonants = [
        'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w',
        'x', 'y', 'z',
    ];
    let mut rng = rand::thread_rng();
    let length = rng.gen_range(3..=8); // 随机生成单词长度，范围为 3 到 8
    let word: String = (0..length)
        .map(|i| {
            if i % 2 == 0 {
                // 偶数位置选择辅音字母
                consonants[rng.gen_range(0..consonants.len())]
            } else {
                // 奇数位置选择元音字母
                vowels[rng.gen_range(0..vowels.len())]
            }
        })
        .collect();

    word
}
